(function () {
    var io = ppt.io;
    function PropsController() {
        PropsController.super(this);
        this.ASSETS = {
            RES: ASSETS.PROPSERES,
            TYPE: "simple"
        };

        this.BG = null;
        this.data = null;
        this.propspage = null;
        this.propssell = null;
        this.propstab = null;
        this.tabIndex = null;
        this.init();
    }
    Laya.class(PropsController, "Scene.Props", Laya.Sprite);
    var _proto = PropsController.prototype;
    _proto.destroy = function () {
        Laya.Sprite.prototype.destroy.call(this, true);
        
        this.BG = null;
        this.data = null;
        this.propspage = null;
        this.propssell = null;
        this.propstab = null;
        this.tabIndex = null;
    }
    _proto.init = function () {
        this.size(GAME_CONFIG.WIDTH, Laya.stage.height);
        io.register("bag::getBag", this, this.changeData);
        io.register("bag::sell", this, this.sellData);
        io.register("bag::sort", this, this.changeData);
    }
    _proto.changeData = function (data) {
        this.data = data;
        this.propspage.upData(data);
        this.propssell.visibleSell(data.bag);
        this.propssell.upData(data.bag[0]);
    }
    _proto.finishingEd = function () {
        io.emit({ "cmd": "bag::sort", params: { 'type': (this.tabIndex + 1) } });
    }

    //出售结果
    _proto.sellData = function () {
        // this.propssell.sellSuccess(this.tabIndex);
        io.emit({ "cmd": "bag::getBag", params: { 'type': this.tabIndex + 1 } });
        io.emit({ "cmd": "game::enter", params: {} });
    }
    _proto.onAdd = function () {
        var BG = utils.createSkeleton('res/public/public_bg');
        BG.pos(GAME_CONFIG.WIDTH / 2, Laya.stage.height / 2);
        BG.play('public_bg', true);
        this.BG = BG;

        var propssell = new Com.Props.Sell();
        propssell.right = 10;
        propssell.top = 95;
        this.propssell = propssell;

        var propspage = new Com.Props.Page(function (index) {
            this.propssell.upData(this.data.bag[index]);
        }.bind(this));
        propspage.x = 250;
        propspage.top = 95;
        propspage.bottom = 50;
        this.propspage = propspage;

        var propstab = new Com.Props.Tab(function (index) {
            this.propspage.titleChange(index);
            this.tabIndex = index;
        }.bind(this));
        propstab.x = 10;
        propstab.top = 130;
        propstab.bottom = 100;
        this.propstab = propstab;

        this.addChildren(BG, propspage, propstab, propssell);
    }
    _proto.onEnter = function () {
        io.emit({ "cmd": "bag::getBag", params: { 'type': 1 } });
        ppt.header.enter("props");
    }
    _proto.onExit = function () {
        this.destroy(true);

        this.BG = null;
        this.data = null;
        this.propspage = null;
        this.propssell = null;
        this.propstab = null;
        this.tabIndex = null;

        io.unregister("bag::getBag");
        io.unregister("bag::sell");
        io.unregister("bag::sort");
    }
    _proto.onResize = function (height) {
        this.height = height;

        this.BG.x = 667;
        this.BG.y = height / 2;

        this.propstab.top = 130;
        this.propstab.bottom = 100;

        this.propspage.top = 95;
        this.propspage.bottom = 50;
    }
})();
